package cn.edu.scau.cmi.luochenghao.chapter05;

class Village {
	static int treeAmount;
	int peopleNumber;
	String name;

	Village(String s) {
		name = s;
	}

	void treePlanting(int n) {
		treeAmount += n;
		System.out.println(name + "植树" + n + "颗");
	}

	void fellTree(int n) {
		if (treeAmount - n >= n) {
			treeAmount -= n;
			System.out.println(name + "伐树" + n + "颗");
		}
		else {
			System.out.println("无树木可伐");
		}
	}
	static int lookTreeAmount() {
		return treeAmount;
	}
	void addPeopleNumber(int n) {
		peopleNumber+=n;
		System.out.println(name + "增加了" + n + "人");
	}
}

public class MainClass {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Village zhaoZhuang,maJiaHeZhi;
		zhaoZhuang=new Village("赵庄");
		maJiaHeZhi=new Village("马家河子");
		zhaoZhuang.peopleNumber=100;
		maJiaHeZhi.peopleNumber=150;
		Village.treeAmount=200;
		int leftTree=Village.treeAmount;
		System.out.println("森林中有"+ leftTree +"颗树");
		zhaoZhuang.treePlanting(50);
		leftTree=maJiaHeZhi.lookTreeAmount();
		System.out.println("森林中有"+ leftTree +"颗树");
		maJiaHeZhi.fellTree(70);
		leftTree=maJiaHeZhi.lookTreeAmount();
		System.out.println("森林中有"+ leftTree +"颗树");
		System.out.println("赵庄的人口："+zhaoZhuang.peopleNumber);
		zhaoZhuang.addPeopleNumber(12);
		System.out.println("赵庄的人口："+zhaoZhuang.peopleNumber);
		System.out.println("马家河子的人口："+maJiaHeZhi.peopleNumber);
		maJiaHeZhi.addPeopleNumber(10);
		System.out.println("马家河子的人口："+maJiaHeZhi.peopleNumber);
		
	}

}
